package com.s06.homework.model;

import java.util.Date;
import com.s06.homework.utils.*;

public class User {

	private String name;
	private String surname;
	private String dob;
	private long timeCreated;
	private long timeUpdated;
	private int age;
	
	public User(String string) {
		
		String[] entries = string.split(",");
		
		name = entries[0];
		surname = entries[1];
		dob = entries[2];
		timeCreated = new Date().getTime();
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name.toUpperCase();
	}

	public String getSurname() {
		return surname;
	}

	public void setSurname(String surname) {
		this.surname = surname.toLowerCase();
		timeUpdated = new Date().getTime();
	}
	
	public long getTimeUpdated(){
		return timeUpdated;
	}

	public void setTimeUpdated(long timeUpdated){
		long now = new Date().getTime();
		this.timeUpdated = now - timeUpdated;
	}
	
	public long getTimeCreated(){
		return timeCreated;
	}

	public void setTimeCreated(long timeCreated){
		long now = new Date().getTime();
		this.timeCreated = now - timeCreated;
	}
		
	public Integer getAge(){
		return age;
	}
	
	public void setAge(int age){
		this.age = UserUtils.getAge(this.dob);
	}
	
	public String toString() {
		name = getName();
		setName(name);

		surname = getSurname();
		setSurname(surname);

		age = getAge();
		setAge(age);
		
		timeCreated = getTimeCreated();
		setTimeCreated(timeCreated);

		timeUpdated = getTimeUpdated();
		setTimeUpdated(timeUpdated);
		
		return "Hello " + name + " " + surname + ". You are " + age + " years old. Your account has been created " + timeCreated + "ms ago. Last update was " + timeUpdated + "ms ago.";
	}

	
}
